package com.lj.ljminsu.controller;


import com.lj.ljminsu.Bean.RoomDetilsDire;
import com.lj.ljminsu.service.impl.RoomServiceImpl;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {
    @Resource
    private RoomServiceImpl roomService;


    @RequestMapping("roomdetilsdire")
    public List<RoomDetilsDire> goodList(@RequestParam("s") Integer s
    ) {
//        System.out.println(s);
        List<RoomDetilsDire> roomDetilsDires = roomService.selectRoomDetilByRenshu(s);

        for (RoomDetilsDire room : roomDetilsDires) {
            Integer bedNum = room.getBedNum();
            String s1 = bedNum.toString();
            String s2 = transition(s1);
            room.setBedNumStr(s2);
        }
        return roomDetilsDires;


    }


    public static String transition(String si) {
        String[] aa = {"", "十", "百", "千", "万", "十万", "百万", "千万", "亿", "十亿"};
        String[] bb = {"一", "二", "三", "四", "五", "六", "七", "八", "九"};
        char[] ch = si.toCharArray();
        int maxindex = ch.length;
        // 字符的转换
        //两位数的特殊转换
        if (maxindex == 2) {
            for (int i = maxindex - 1, j = 0; i >= 0; i--, j++) {
                if (ch[j] != 48) {
                    if (j == 0 && ch[j] == 49) {
                        return aa[i];
                    } else {
                        return (bb[ch[j] - 49] + aa[i]);
                    }
                }
            }
        //其他位数的特殊转换，使用的是int类型最大的位数为十亿
        } else {
            for (int i = maxindex - 1, j = 0; i >= 0; i--, j++) {
                if (ch[j] != 48) {
                    return (bb[ch[j] - 49] + aa[i]);
                }
            }
        }
        return null;
    }

}
